package parser;

import global.Methods;

import java.util.ArrayList;

/**@author A0105661M*/
public class IndexAnalyzer {

	public static boolean isAll(String[] commandContent) {
		if (commandContent == null || commandContent.length == 0) {
			return false;
		}
		if (commandContent[0].equalsIgnoreCase("all")) {
			return true;
		}

		return false;
	}

	public static ArrayList<Integer> analyzeIndex(String[] commandContent) {
		ArrayList<Integer> indexArray = new ArrayList<Integer>();

		if (commandContent != null) {
			for (int i = 0; i < commandContent.length; i++) {
				int index = Methods.safeParseInt(commandContent[i]);
				if (index != -1 && notInArrayList(index, indexArray)) {
					indexArray.add(index);
				}
			}
		}

		return indexArray;
	}

	private static boolean notInArrayList(int index,
			ArrayList<Integer> indexArray) {
		return indexArray.indexOf(index) == -1;
	}

}
